Answer:

New Example: Fat Calculator

Fat Calculator GUI

The answer is (I hope) obvious. It is a good idea to keep the GUI code and the application code in separate modules to help in debugging and understanding the program. This is also helpful if you later need to make changes to the program, say changing it from an application to an applet. The application code can be carried over without change.

Let us develop another GUI application. Health experts recommend that the food you eat have less than 30% of its total calories in fat. Our new application calculates the percentage of calories that come from fat, given the number of grams of fat and the number of calories per serving of a food. Most packaged foods display these values on their label. Fat contains 9 calories per gram.

  1. Input:
    • Calories per serving.
    • Grams of fat per serving.
  2. Calculation:
    • percent = ( (fat * 9) / calories ) * 100
  3. Output:
    • percent of fat from calories

QUESTION 8:

What data type should be used for the variables and for the calculation?